package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.SkuService;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;
import com.junzhiit.nengji.cms.web.vo.SkuAddVO;
import com.junzhiit.nengji.cms.web.vo.SkuEditVO;
import com.junzhiit.nengji.cms.web.vo.SkuListVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/sku")
public class SkuController extends BaseController {
	@Autowired
	private SkuService skuService;

	@ApiOperation(value = "获取SKU分类")
	@RequestMapping(method = RequestMethod.GET)
	public Map<String, Object> findAll(DataTablesParamVO dtp, SkuListVO skuListVO) {
		return skuService.findAll(dtp, skuListVO);
	}

	@ApiOperation(value = "增加SKU名称")
	@RequestMapping(method = RequestMethod.POST)
	public ResultVO add(SkuAddVO skuAddVO) {
		return skuService.add(skuAddVO);
	}

	@ApiOperation(value = "修改SKU名称")
	@RequestMapping(method = RequestMethod.PUT)
	public ResultVO update(SkuEditVO skuEditVO) {
		AssertUtil.notBlank(skuEditVO.getName(), "name is required.");
		return skuService.update(skuEditVO);
	}

	@ApiOperation(value = "删除SKU分类")
	@RequestMapping(value = "/delete", method = RequestMethod.PUT)
	public ResultVO delete(String id) {
		return skuService.delete(id);
	}

	@ApiOperation(value = "批量删除sku分类")
	@RequestMapping(value = "/batch/delete", method = RequestMethod.PUT)
	public ResultVO batchDelete(String[] ids) {
		return skuService.batchDelete(ids);
	}
	
	@RequestMapping(value="/all",method=RequestMethod.GET)
	public ResultVO getAll(String sessionId){
		return skuService.getAll(sessionId);
	}
	
	@RequestMapping(value="/use/count",method=RequestMethod.GET)
	public ResultVO queryGoodsAboutSkuCount(String skuId){
		return skuService.queryGoodsAboutSkuCount(skuId);
	}
}
